{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Number of Different Integers in a String"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #hash-table #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #哈希表 #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: numDifferentIntegers"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #字符串中不同整数的数目"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个字符串 <code>word</code> ，该字符串由数字和小写英文字母组成。</p>\n",
    "\n",
    "<p>请你用空格替换每个不是数字的字符。例如，<code>\"a123bc34d8ef34\"</code> 将会变成 <code>\" 123  34 8  34\"</code> 。注意，剩下的这些整数为（相邻彼此至少有一个空格隔开）：<code>\"123\"</code>、<code>\"34\"</code>、<code>\"8\"</code> 和 <code>\"34\"</code> 。</p>\n",
    "\n",
    "<p>返回对 <code>word</code> 完成替换后形成的 <strong>不同</strong> 整数的数目。</p>\n",
    "\n",
    "<p>只有当两个整数的 <strong>不含前导零</strong> 的十进制表示不同， 才认为这两个整数也不同。</p>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>word = \"a<strong>123</strong>bc<strong>34</strong>d<strong>8</strong>ef<strong>34</strong>\"\n",
    "<strong>输出：</strong>3\n",
    "<strong>解释：</strong>不同的整数有 \"123\"、\"34\" 和 \"8\" 。注意，\"34\" 只计数一次。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>word = \"leet<strong>1234</strong>code<strong>234</strong>\"\n",
    "<strong>输出：</strong>2\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>word = \"a<strong>1</strong>b<strong>01</strong>c<strong>001</strong>\"\n",
    "<strong>输出：</strong>1\n",
    "<strong>解释：</strong>\"1\"、\"01\" 和 \"001\" 视为同一个整数的十进制表示，因为在比较十进制值时会忽略前导零的存在。\n",
    "</pre>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 <= word.length <= 1000</code></li>\n",
    "\t<li><code>word</code> 由数字和小写英文字母组成</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [number-of-different-integers-in-a-string](https://leetcode.cn/problems/number-of-different-integers-in-a-string/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [number-of-different-integers-in-a-string](https://leetcode.cn/problems/number-of-different-integers-in-a-string/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"a123bc34d8ef34\"', '\"leet1234code234\"', '\"a1b01c001\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        new_word = ''\n",
    "        for ch in word:\n",
    "            if ch.isdigit():\n",
    "                new_word+=ch\n",
    "            else:\n",
    "                new_word+=' '\n",
    "        ints = new_word.split()\n",
    "        cnt = 0\n",
    "        ints_set = set()\n",
    "        for i in ints:\n",
    "            if int(i) not in ints_set:\n",
    "                cnt+=1\n",
    "                ints_set.add(int(i))\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        ans = set()\n",
    "        a = ''\n",
    "        for i in word:\n",
    "            if 47<ord(i)<58:\n",
    "                a += i\n",
    "            else:\n",
    "                if a:\n",
    "                    ans.add(int(a))\n",
    "                a = ''\n",
    "        if a:\n",
    "            ans.add(int(a))\n",
    "        return len(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        return len(set(map(int,re.findall(\"[0-9]+\",word))))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        \n",
    "        dic={}\n",
    "        cnt=0\n",
    "        s=''\n",
    "        i=0\n",
    "        while i < len(word):\n",
    "            if '0'<=word[i]<='9':\n",
    "                j=i\n",
    "                while j<len(word) and '0'<=word[j]<='9':\n",
    "                    j+=1\n",
    "                k=int(word[i:j])\n",
    "                if k in dic:\n",
    "                    dic[k]+=1\n",
    "                else:\n",
    "                    dic[k]=1\n",
    "                i=j-1\n",
    "            i+=1\n",
    "        return len(dic)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        s = set()\n",
    "        st = 0\n",
    "        word = 'a' + word + 'a'\n",
    "        for i in range(1,len(word)):\n",
    "            if word[i] in '0123456789':\n",
    "                if not st:\n",
    "                    st = i\n",
    "            else:\n",
    "                if st:\n",
    "                    s.add(int(word[st:i]))\n",
    "                    st = 0\n",
    "        return len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        re1 = re.findall(r\"\\d*\",word)\n",
    "        list1= []\n",
    "        for i in re1:\n",
    "            if i != \"\":\n",
    "                list1.append(int(i))\n",
    "        return len(set(list1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        for i in range(len(word)):\n",
    "            if word[i].isalpha():\n",
    "                word = word[:i:] + ' ' + word[i+1::]\n",
    "        l = set(list(map(int,word.split())))\n",
    "        return len(l)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        return len(set(map(int, re.findall('\\d+', word))))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        for ch in word:\n",
    "            if ch.isalpha():\n",
    "                word = word.replace(ch, \" \")\n",
    "        return len(set([int(i) for i in word.split()]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        s=set()\n",
    "        i,n=0,len(word)\n",
    "        while i<n:\n",
    "            if word[i].isdigit():\n",
    "                while i<n and word[i]=='0':\n",
    "                    i+=1\n",
    "                j=i\n",
    "                while j<n and word[j].isdigit():\n",
    "                    j+=1\n",
    "                s.add(word[i:j])\n",
    "                i=j\n",
    "            i+=1\n",
    "        return len(s)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        s = set()\n",
    "        n = len(word)\n",
    "        p1 = 0\n",
    "        while True:\n",
    "            while p1 < n and not word[p1].isdigit():\n",
    "                p1 += 1\n",
    "            if p1 == n:\n",
    "                break\n",
    "            p2 = p1\n",
    "            while p2 < n and word[p2].isdigit():\n",
    "                p2 += 1\n",
    "            while p2 - p1 > 1 and word[p1] == '0':  # 去除前导 0\n",
    "                p1 += 1\n",
    "            s.add(word[p1:p2])\n",
    "            p1 = p2\n",
    "        return len(s)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        cnt = set()\n",
    "        j = re.split(\"[a-z]+\", word)\n",
    "        for i in j:\n",
    "            if i != \"\":\n",
    "                cnt.add(int(i))\n",
    "        return len(cnt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import re\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        ns = [int(x) for x in re.findall(r'\\d+',word)]\n",
    "        return len(set(ns))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        word = list(map(lambda x: \" \" if x.isalpha() else x, word))\n",
    "        word = \"\".join(word).split()\n",
    "        word = [int(i) for i in word]\n",
    "        return len(set(word))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        s = set()\n",
    "        st = 0\n",
    "        word = 'a' + word + 'a'\n",
    "        for i in range(1,len(word)):\n",
    "            if word[i] in '0123456789':\n",
    "                if not st:\n",
    "                    st = i\n",
    "            else:\n",
    "                if st:\n",
    "                    s.add(int(word[st:i]))\n",
    "                    st = 0\n",
    "        return len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        new_word = \"\"\n",
    "\n",
    "        for elem in word:\n",
    "            if str.isdigit(elem):\n",
    "                new_word += elem\n",
    "            else:\n",
    "                new_word += \" \"\n",
    "        \n",
    "        new_word = new_word.split()\n",
    "        for idx in range(len(new_word)):\n",
    "            new_word[idx] = int(new_word[idx])\n",
    "        \n",
    "        dic_new_word = collections.Counter(new_word)\n",
    "\n",
    "        return len(dic_new_word)\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        i = 0\n",
    "        pre = 0\n",
    "        nums = set()\n",
    "        while i < len(word):\n",
    "            while i < len(word) and word[i].isdigit():\n",
    "                i += 1\n",
    "            if i != pre:\n",
    "                nums.add(int(word[pre:i]))\n",
    "            while i < len(word) and word[i].isalpha():\n",
    "                i += 1\n",
    "            pre = i\n",
    "        # print(nums)\n",
    "        return len(nums)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        x = \"\"\n",
    "        l1 = set()\n",
    "        for i in range (len(word)):\n",
    "            if word[i].isalpha() and len(x) != 0:\n",
    "                l1.add(int(x))\n",
    "                x = \"\"\n",
    "            if word[i].isdigit():\n",
    "                x += word[i]\n",
    "        if len(x) != 0:\n",
    "            l1.add(int(x))\n",
    "        return len(l1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        lst=list(word)\n",
    "        lstnum=[\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\"]\n",
    "        for i in range(len(lst)):\n",
    "            if lst[i] not in lstnum:\n",
    "                lst[i]=\" \"\n",
    "        word=''.join(lst)\n",
    "        word=word.split()\n",
    "        anslst=[]\n",
    "        for i in word:\n",
    "            anslst.append(int(i))\n",
    "        return len(set(anslst))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        # 双指针\n",
    "        res = set()\n",
    "        x_index = 0\n",
    "        y_index = 1\n",
    "        while x_index < len(word):\n",
    "            if '0' <= word[x_index] <= '9':\n",
    "                y_index = x_index + 1\n",
    "                while y_index < len(word):\n",
    "                    if '0' <= word[y_index] <= '9':\n",
    "                        y_index += 1\n",
    "                        continue\n",
    "                    break\n",
    "                res.add(int(word[x_index: y_index]))\n",
    "                x_index = y_index + 1\n",
    "            else:\n",
    "                x_index += 1\n",
    "        return len(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        nums = []\n",
    "        n = len(word)\n",
    "        i, j = 0,0\n",
    "        while j<n:\n",
    "            while i<n and not word[i].isdigit():\n",
    "                i += 1\n",
    "            j = i+1\n",
    "            while j<n and word[j].isdigit():\n",
    "                j += 1\n",
    "            if i==n:\n",
    "                break\n",
    "            numstr = word[i:j].lstrip(\"0\") \n",
    "            numstr = numstr if numstr else \"0\"\n",
    "            num = int(numstr)\n",
    "            if num not in nums:\n",
    "                nums.append(num)\n",
    "            i = j\n",
    "        return len(nums)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        num_set = set()\n",
    "        cur_num = None\n",
    "        len_w = len(word)\n",
    "        for i in range(len_w):\n",
    "            tmp = ord(word[i])\n",
    "            if 48 <= tmp <= 57 and cur_num is None:\n",
    "                cur_num = word[i]\n",
    "            elif 48 <= tmp <= 57 and cur_num is not None:\n",
    "                cur_num += word[i]\n",
    "            elif cur_num is not None:\n",
    "                cur_num = int(cur_num)\n",
    "                num_set.add(cur_num)\n",
    "                cur_num = None\n",
    "            if i == len_w - 1 and cur_num is not None:\n",
    "                cur_num = int(cur_num)\n",
    "                num_set.add(cur_num)\n",
    "        return len(num_set)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        s = set()\n",
    "        st = 0\n",
    "        word = 'a' + word + 'a'\n",
    "        for i in range(1,len(word)):\n",
    "            if word[i] in '0123456789':\n",
    "                if not st:\n",
    "                    st = i\n",
    "            else:\n",
    "                if st:\n",
    "                    s.add(int(word[st:i]))\n",
    "                    st = 0\n",
    "        return len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        res = [ int(i) for i in re.findall('(\\d+)',word)]\n",
    "        res = list(set(res))\n",
    "        return len(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        return len(set(map(int, findall('\\d+', word))))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        return len(set(map(int,re.findall(\"[0-9]+\",word))))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "      \n",
    "      d = {}\n",
    "      cnt = 0\n",
    "      start = 0\n",
    "\n",
    "      while start < len(word):\n",
    "        tmp = \"\"\n",
    "        while start < len(word) and word[start].isdigit():\n",
    "            tmp += word[start]\n",
    "            start += 1\n",
    "\n",
    "        if tmp:\n",
    "           itmp = int(tmp)\n",
    "        if tmp and itmp not in d:\n",
    "           d[itmp] = 1\n",
    "           cnt += 1\n",
    "        start += 1\n",
    "      return cnt\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        lst = []\n",
    "        for c in word:\n",
    "            if c.isalpha():\n",
    "                lst.append(\" \")\n",
    "            else:\n",
    "                lst.append(c)\n",
    "        s = \"\".join(lst).split(\" \")\n",
    "        ans = set()\n",
    "        for c in s:\n",
    "            if c:\n",
    "                ans.add(int(c))\n",
    "        return len(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "      \n",
    "      set1 = set()\n",
    "      cnt = 0\n",
    "      start = 0\n",
    "\n",
    "      while start < len(word):\n",
    "        tmp = \"\"\n",
    "        while start < len(word) and word[start].isdigit():\n",
    "            tmp += word[start]\n",
    "            start += 1\n",
    "\n",
    "        if tmp:\n",
    "          set1.add(int(tmp))\n",
    "        start += 1\n",
    "      return len(set1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        s,p=set(),0\n",
    "        while(p<len(word)):\n",
    "            while p<len(word) and ord(word[p])>57:\n",
    "                p+=1\n",
    "            r=p\n",
    "            if p<len(word):\n",
    "                while r<len(word) and ord(word[r])<58:\n",
    "                    r+=1\n",
    "                s.add(int(word[p:r]))\n",
    "                p=r\n",
    "        return len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        s = set()\n",
    "        n = len(word)\n",
    "        p1 = 0\n",
    "        while True:\n",
    "            while p1 < n and not word[p1].isdigit():\n",
    "                p1 += 1\n",
    "            if p1 == n:\n",
    "                break\n",
    "            p2 = p1\n",
    "            while p2 < n and word[p2].isdigit():\n",
    "                p2 += 1\n",
    "            while p2 - p1 > 1 and word[p1] == '0':  # 去除前导 0\n",
    "                p1 += 1\n",
    "            s.add(word[p1:p2])\n",
    "            p1 = p2\n",
    "        return len(s)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import re\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        lis = re.split(r\"\\D+\", word)\n",
    "        res = set()\n",
    "        for i in lis:\n",
    "            if i != \"\":\n",
    "                res.add(int(i))\n",
    "        return len(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        lst = set()\n",
    "        i, j = 0, 0\n",
    "        while j < len(word):\n",
    "            if not word[j].isdigit():\n",
    "                if word[i].isdigit():\n",
    "                    lst.add(int(word[i: j]))\n",
    "                i = j\n",
    "            else:\n",
    "                if not word[i].isdigit():\n",
    "                    i = j\n",
    "            j += 1\n",
    "        if word[i].isdigit():\n",
    "            lst.add(int(word[i:]))\n",
    "        return len(lst)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "      \n",
    "      d = {}\n",
    "      cnt = 0\n",
    "      start = 0\n",
    "\n",
    "      while start < len(word):\n",
    "        tmp = \"\"\n",
    "        while start < len(word) and word[start].isdigit():\n",
    "            tmp += word[start]\n",
    "            start += 1\n",
    "\n",
    "\n",
    "        if tmp and int(tmp) not in d:\n",
    "           d[int(tmp)] = 1\n",
    "           cnt += 1\n",
    "        start += 1\n",
    "      return cnt\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        output_str = re.sub(r'[a-zA-Z]', ' ', word)\n",
    "        lst = output_str.split()\n",
    "        for i in range(len(lst)):\n",
    "            lst[i] = int(lst[i])\n",
    "        \n",
    "        return len(set(lst))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        return len(set(map(int,re.findall(\"[0-9]+\",word))))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        s = ''\n",
    "        date_list = []\n",
    "        for date in word:\n",
    "            try:\n",
    "                s += str(int(date))\n",
    "            except:\n",
    "                date_list.append(s)\n",
    "                s = ''\n",
    "\n",
    "        date_list.append(s)\n",
    "        \n",
    "\n",
    "\n",
    "        sum = []\n",
    "        for date in date_list:\n",
    "            try:\n",
    "                sum.append(int(date))\n",
    "            except:\n",
    "                pass\n",
    "        return len(set(sum))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        x=[]\n",
    "        s = ''\n",
    "        for i in word:\n",
    "            if i.isdigit():\n",
    "                s+=i\n",
    "            else:\n",
    "                if len(s)!=0:\n",
    "                    x.append(int(s))\n",
    "                    s=''\n",
    "        if len(s)!=0:\n",
    "            x.append(int(s))\n",
    "        return len(set(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        numbers = defaultdict(int) \n",
    "        clip = -1\n",
    "        for i in range(len(word)):\n",
    "            if (word[i] >= '0' and word[i] <= '9') and clip == -1:\n",
    "                clip = i\n",
    "            if (word[i] < '0' or word[i] > '9') and clip != -1:\n",
    "                num = int(word[clip:i])\n",
    "                numbers[num] += 1\n",
    "                clip = -1\n",
    "        if clip != -1:\n",
    "            num = int(word[clip:])\n",
    "            numbers[num] += 1\n",
    "\n",
    "        return len(numbers.keys())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import re\r\n",
    "\r\n",
    "class Solution:\r\n",
    "    def numDifferentIntegers(self, word: str) -> int:\r\n",
    "        texts = [int(x) for x in re.split(\"[a-z]+\", word) if x]\r\n",
    "        return len(set(texts))\r\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "      \n",
    "      d = {}\n",
    "      cnt = 0\n",
    "      start = 0\n",
    "\n",
    "      while start < len(word):\n",
    "        tmp = \"\"\n",
    "        while start < len(word) and word[start].isdigit():\n",
    "            tmp += word[start]\n",
    "            start += 1\n",
    "\n",
    "        if tmp:\n",
    "           itmp = int(tmp)\n",
    "        if tmp and itmp not in d:\n",
    "           d[itmp] = 1\n",
    "           cnt += 1\n",
    "           \n",
    "        start += 1\n",
    "      return cnt\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        lst = set()\n",
    "        i, j = 0, 0\n",
    "        while j < len(word):\n",
    "            if not word[j].isdigit() and word[i].isdigit():\n",
    "                lst.add(int(word[i: j]))\n",
    "                i = j\n",
    "            elif not word[i].isdigit():\n",
    "                i = j\n",
    "            j += 1\n",
    "        if word[i].isdigit():\n",
    "            lst.add(int(word[i:]))\n",
    "        return len(lst)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        import re\n",
    "        wl = list(filter(lambda x : x != '', re.sub(r'[a-z]', ' ', word).split(' ')))\n",
    "        return len(set([int(i) for i in wl]))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import re\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        # lis = re.split(r\"\\D+\", word)\n",
    "        # res = set()\n",
    "        # for i in lis:\n",
    "        #     if i != \"\":\n",
    "        #         res.add(int(i))\n",
    "        # return len(res)\n",
    "        # lis = re.findall(r\"\\d+\", word)\n",
    "        # res = set()\n",
    "        # for i in lis:\n",
    "        #     res.add(int(i))\n",
    "        # return len(res)\n",
    "\n",
    "        i, m = 0, len(word)\n",
    "        lis = set()\n",
    "        while i < m:\n",
    "            if word[i].isdigit():\n",
    "                while i < m and word[i] == '0':\n",
    "                    i = i + 1\n",
    "                j = i\n",
    "                while j < m and word[j].isdigit():\n",
    "                    j = j + 1\n",
    "                lis.add(word[i:j])\n",
    "                i = j\n",
    "            i = i + 1\n",
    "        return len(lis)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        lst = []\n",
    "        for c in word:\n",
    "            if c.isalpha():\n",
    "                lst.append(\" \")\n",
    "            else:\n",
    "                lst.append(c)\n",
    "        s = \"\".join(lst).split(\" \")\n",
    "        ans = set()\n",
    "        for c in s:\n",
    "            if c:\n",
    "                ans.add(int(c))\n",
    "        return len(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        x = \"\"\n",
    "        l1 = set()\n",
    "        for i in range (len(word)):\n",
    "            if word[i].isalpha() and len(x) != 0:\n",
    "                l1.add(int(x))\n",
    "                x = \"\"\n",
    "            if word[i].isdigit():\n",
    "                x += word[i]\n",
    "        if len(x) != 0:\n",
    "            l1.add(int(x))\n",
    "        return len(l1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "\n",
    "        pos = 1\n",
    "        result = []\n",
    "        cur = 0\n",
    "        while pos < len(word):\n",
    "            if word[pos].isalpha() and word[pos-1].isdigit():\n",
    "                result.append(int(word[cur:pos]))\n",
    "            \n",
    "            if word[pos].isdigit() and word[pos-1].isalpha():\n",
    "                cur = pos\n",
    "            \n",
    "            pos += 1\n",
    "        if word[-1].isdigit():\n",
    "            result.append(int(word[cur:pos]))\n",
    "        \n",
    "        return len(set(result))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        save = set()\n",
    "        i1 = 0\n",
    "        for i in range(len(word)):\n",
    "            if word[i].isdigit() and word[i1].isalpha():\n",
    "                i1 = i\n",
    "            elif word[i].isalpha() and word[i1].isdigit():\n",
    "                save.add(int(word[i1:i]))\n",
    "                i1 = i \n",
    "        if word[i1:].isdigit():\n",
    "            save.add(int(word[i1:]))\n",
    "        return len(save)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        s = set()\n",
    "        n = len(word)\n",
    "        p1 = 0\n",
    "        while True:\n",
    "            while p1 < n and not word[p1].isdigit():\n",
    "                p1 += 1\n",
    "            if p1 == n:\n",
    "                break\n",
    "            p2 = p1\n",
    "            while p2 < n and word[p2].isdigit():\n",
    "                p2 += 1\n",
    "            while p2 - p1 > 1 and word[p1] == '0':  # 去除前导 0\n",
    "                p1 += 1\n",
    "            s.add(word[p1:p2])\n",
    "            p1 = p2\n",
    "        return len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        list2=[]\n",
    "        for char in word:\n",
    "            if char in ascii_lowercase:\n",
    "                word = word.replace(char, \" \")\n",
    "        list1=word.split(\" \")\n",
    "        for i in list1:\n",
    "            if i==\"\":\n",
    "                continue\n",
    "            else:\n",
    "                list2.append(int(i))\n",
    "        set1=set(tuple(list2))\n",
    "        return len(set1)\n",
    "\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, words: str) -> int:\n",
    "        s = set()\n",
    "        current_num = ''\n",
    "        # 遍历字符串\n",
    "        for char in words:\n",
    "            if char.isdigit():\n",
    "                current_num += char\n",
    "            elif current_num:\n",
    "                s.add(int(current_num))\n",
    "                current_num = ''\n",
    "        # 添加最后一个数字（如果存在）\n",
    "        if current_num:\n",
    "            s.add(int(current_num))\n",
    "\n",
    "        return len(s)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        output_str = re.sub(r'[a-zA-Z]', ' ', word)\n",
    "        lst = output_str.split()\n",
    "        for i in range(len(lst)):\n",
    "            lst[i] = int(lst[i])\n",
    "        \n",
    "        return len(set(lst))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        import re \n",
    "        nums = re.findall(\"\\d+\", word)\n",
    "        return len(set(map(int, nums)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "                s = set()\n",
    "                i = 0\n",
    "                n = len(word)\n",
    "                while i < n:\n",
    "                    \n",
    "                    if word[i].isdigit():\n",
    "                        j = i\n",
    "                        while j<n and  word[j].isdigit():\n",
    "                            j += 1\n",
    "                        s.add(int(word[i:j]))\n",
    "                        \n",
    "                        i = j\n",
    "                    else: i += 1\n",
    "                return len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        new = re.sub('[a-z]', ' ', word).strip()\n",
    "        slow, fast, n = 0, 0, len(new)\n",
    "        res = []\n",
    "        while fast<n:\n",
    "            while new[fast]==\" \" and fast<n:\n",
    "                fast+=1\n",
    "            slow=fast\n",
    "            while new[fast]!=\" \" and fast<n:\n",
    "                fast+=1\n",
    "                if fast==n:\n",
    "                    break\n",
    "            st=new[slow:fast]\n",
    "            count = 0\n",
    "            for i in range(len(st)):\n",
    "                if int(st[i]) == 0:\n",
    "                    count += 1\n",
    "            res.append(new[slow:fast][count:])\n",
    "        ans=set(res)\n",
    "        return len(ans)\n",
    "\n",
    "# 解法 2\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        n=len(word)\n",
    "        st=list(word)\n",
    "        for i in range(n):\n",
    "            if st[i].isalpha():\n",
    "                st[i]=\" \"\n",
    "        nums=''.join(map(str,st)).strip()\n",
    "        nums=nums.split()\n",
    "        ans=[]\n",
    "        # 逐个转成 int 加到列表里，去掉数字前面的 0\n",
    "        # ['1', '01', '001']->[1, 1, 1]\n",
    "        for num in nums:\n",
    "            ans.append(int(num))\n",
    "        print(ans)\n",
    "        return len(set(ans))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        res = set()\n",
    "        num_machine = str()\n",
    "        for char in word:\n",
    "            if char < '0' or char > '9':\n",
    "                if num_machine:\n",
    "                    res.add(int(num_machine))\n",
    "                    num_machine = ''\n",
    "\n",
    "            else:\n",
    "                if len(num_machine) == 1 and num_machine[0] == '0':\n",
    "                    num_machine = ''\n",
    "\n",
    "                num_machine += char\n",
    "\n",
    "        if num_machine:\n",
    "            res.add(int(num_machine))\n",
    "\n",
    "        return len(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "\n",
    "        pos = 1\n",
    "        result = []\n",
    "        cur = 0\n",
    "        while pos < len(word):\n",
    "            if word[pos].isalpha() and word[pos-1].isdigit():\n",
    "                result.append(int(word[cur:pos]))\n",
    "            \n",
    "            if word[pos].isdigit() and word[pos-1].isalpha():\n",
    "                cur = pos\n",
    "            \n",
    "            pos += 1\n",
    "        if word[-1].isdigit():\n",
    "            result.append(int(word[cur:pos]))\n",
    "        \n",
    "        return len(set(result))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        return len(set(map(int, findall('\\d+', word))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        \n",
    "        ans = set()\n",
    "        pre =\"\"\n",
    "        for w in word:\n",
    "            if w.isnumeric():\n",
    "                pre += w\n",
    "            else:\n",
    "                if pre:\n",
    "                    ans.add(int(pre))\n",
    "                pre= \"\"\n",
    "        if pre:\n",
    "            ans.add(int(pre))\n",
    "        return len(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        newWord = \"\"\n",
    "        for i, ch in enumerate(word):\n",
    "            if ch.isalpha():\n",
    "                newWord += \" \"\n",
    "            else:\n",
    "                newWord += ch\n",
    "        ls = newWord.split(\" \")\n",
    "        nums = []\n",
    "        for s in ls:\n",
    "            if not s:\n",
    "                continue\n",
    "            s = s.lstrip(\"0\")\n",
    "            if not s:\n",
    "                s = \"0\"\n",
    "            if s not in nums:\n",
    "                nums.append(s)\n",
    "        return len(nums)\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        numbers = {}\n",
    "        clip = -1\n",
    "        for i in range(len(word)):\n",
    "            if (word[i] >= '0' and word[i] <= '9') and clip == -1:\n",
    "                clip = i\n",
    "            if (word[i] < '0' or word[i] > '9') and clip != -1:\n",
    "                num = int(word[clip:i])\n",
    "                numbers[num] = numbers.get(num, 0) + 1\n",
    "                clip = -1\n",
    "        if clip != -1:\n",
    "            num = int(word[clip:])\n",
    "            numbers[num] = numbers.get(num, 0) + 1\n",
    "\n",
    "        return len(numbers.keys())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import re\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        patt = r'[a-zA-Z]+'\n",
    "        digit_lst = re.split(patt, word)\n",
    "        print(digit_lst)\n",
    "        while '' in digit_lst:\n",
    "            digit_lst.remove('')\n",
    "        print(digit_lst)\n",
    "        print(set(map(int, digit_lst)))\n",
    "        #print(set(digit_lst))\n",
    "        return len(set(map(int, digit_lst)))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "      \n",
    "      d = {}\n",
    "      cnt = 0\n",
    "      start = 0\n",
    "\n",
    "      while start < len(word):\n",
    "        tmp = \"\"\n",
    "        while start < len(word) and word[start].isdigit():\n",
    "            tmp += word[start]\n",
    "            start += 1\n",
    "\n",
    "        if tmp:\n",
    "           itmp = int(tmp)\n",
    "        if tmp and itmp not in d:\n",
    "           d[itmp] = 1\n",
    "           cnt += 1\n",
    "           \n",
    "        start += 1\n",
    "      return cnt\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        n = len(word)\n",
    "        nums = set()\n",
    "        i = 0\n",
    "        while i < n:\n",
    "            while i < n and (word[i] < '0' or word[i] > '9'):\n",
    "                i += 1\n",
    "            if i >= n:\n",
    "                break\n",
    "            j = i + 1\n",
    "            while j < n and '0' <= word[j] <= '9':\n",
    "                j += 1         \n",
    "            nums.add(int(word[i:j]))\n",
    "            i = j + 1\n",
    "        return len(nums)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "      \n",
    "      d = {}\n",
    "      cnt = 0\n",
    "      start = 0\n",
    "\n",
    "      while start < len(word):\n",
    "        tmp = \"\"\n",
    "        while start < len(word) and word[start].isdigit():\n",
    "            tmp += word[start]\n",
    "            start += 1\n",
    "\n",
    "        if tmp:\n",
    "           itmp = int(tmp)\n",
    "        if tmp and itmp not in d:\n",
    "           d[itmp] = 1\n",
    "           cnt += 1\n",
    "        start += 1\n",
    "      return cnt\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numDifferentIntegers(self, word: str) -> int:\n",
    "        nums = set()\n",
    "        i = 0\n",
    "        n = len(word)\n",
    "        while i < n:\n",
    "            if word[i].isdigit():\n",
    "                tmp = 0\n",
    "                while i < n and word[i].isdigit():\n",
    "                    tmp = tmp * 10 + int(word[i])\n",
    "                    i += 1\n",
    "                nums.add(tmp)\n",
    "            else:\n",
    "                i += 1\n",
    "        return len(nums)\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
